﻿// --------------------------------------------------------------------------------------------------------------------- 
// <copyright file="Problem6.cs" company="Microsoft">
//   Copyright (c) Microsoft Corporation.  All rights reserved. THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
// </copyright>
// <summary>
//   Defines the Problem6 type.
// </summary>
// ---------------------------------------------------------------------------------------------------------------------
namespace EulerProblemsCSharp.Problems
{
    /// <summary>
    /// Problem 6.
    /// </summary>
    public class Problem6 : ProblemBase
    {
        /// <summary>
        /// Gets Number.
        /// </summary>
        /// <value>
        /// The number.
        /// </value>
        public override int Number
        {
            get
            {
                return 6;
            }
        }

        /// <summary>
        /// Gets Description.
        /// </summary>
        /// <value>
        /// The description.
        /// </value>
        public override string Description
        {
            get
            {
                return "Find the difference between the sum of the squares of the first one hundred natural numbers and the square of the sum.";
            }
        }

        /// <summary>
        /// Solves Problem 6.
        /// </summary>
        /// <returns>
        /// The solution.
        /// </returns>
        public override object Solve()
        {
            const int N = 100;
            const int Sum = ((N * N) + N) / 2;
            const int SquareOfSums = Sum * Sum;

            var sumOfSquares = 0;

            for (var i = 1; i <= N; i++)
            {
                checked
                {
                    sumOfSquares = sumOfSquares + (i * i);
                }
            }

            var answer = SquareOfSums - sumOfSquares;
            
            return answer;
        }
    }
}